package com.learn.decorator;

import lombok.extern.slf4j.Slf4j;

/**
 * <p>项目名称: design-pattern </p>
 *
 * <p>文件名称: App </p>
 *
 * The Decorator pattern is a more flexible alternative to subclassing. The Decorator class
 * implements the same interface as the target and uses aggregation to "decorate" calls to the
 * target. Using the Decorator pattern it is possible to change the behavior of the class during
 * runtime.
 * <p>
 * In this example we show how the simple {@link MilkTea} first attacks and then flees the battle.
 * Then we decorate the {@link MilkTea} with a {@link Source} and perform the attack again. You
 * can see how the behavior changes after the decoration.
 */
@Slf4j
public class App {

    public static void main(String[] args) {
        MilkTea milkTea = new MilkTea();
        log.info(String.format("产品是%s,总价是%s",milkTea.getDesc(),milkTea.getPrice()));

        Source s1 = new Source(milkTea, "牛奶",2);
        log.info(String.format("产品是%s,总价是%s",s1.getDesc(),s1.getPrice()));

        Source s2 = new Source(s1, "珍珠",3);
        log.info(String.format("产品是%s,总价是%s",s2.getDesc(),s2.getPrice()));
    }
}
